<?php
class User extends CI_Model {

	public function insertUser($email,$password,$provider_name) {
		$this->load->database();
		$data = array(
				'email' => $email,
				'password' => $password,
				'provider_name' => $provider_name,
		);
		$sql = "SELECT * FROM users WHERE email = ?";
		$query = $this->db->query($sql, array($email,3));
		if ($query->num_rows() > 0) {
			return ErrorMessgaes::$USER_AUTH_EXIST_MSG;
		} else {
			if (!$this->db->insert('users', $data)) {
				return ErrorMessgaes::$INERTNAL_MSG;
			}
		}
	}

	public function insertAdmobUserAcount($email,$admobPassword) {
		$this->load->database();
		$data = array();
		if (isset($admobPassword)) {
			$data = array(
					'email' => $email,
					'acount_password' => $admobPassword,
					'acount_name' => 'admob'
			);
			$sql = "SELECT * FROM users_account_admob WHERE email = ?";
			$query = $this->db->query($sql, array($email));
			if ($query->num_rows() > 0) {
				return ErrorMessgaes::$USER_ACOUNT_EXIST_MSG;
			} else {
				if (!$this->db->insert('users_acount_admob', $data)) {
					return ErrorMessgaes::$INERTNAL_MSG;
				}
			}
		}

	}

	public function insertChartboostUserAcount($email,$chartboostId,$chartboostToken) {
		$this->load->database();
		$data = array();
		if (isset($chartboostId) && isset($chartboostToken)) {
			$data = array(
					'email' => $email,
					'user_id' => $chartboostId,
					'user_sig' => $chartboostToken
			);
			$sql = "SELECT * FROM users_account_chartboost WHERE email = ?";
			$query = $this->db->query($sql, array($email));
			if ($query->num_rows() > 0) {
				return ErrorMessgaes::$USER_ACOUNT_EXIST_MSG;
			} else {
				if (!$this->db->insert('users_account_chartboost', $data)) {
					return ErrorMessgaes::$INERTNAL_MSG;
				}
			}
		}
	}







}